package com.pengtu.gsj.service.impl.system;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.system.LogDao;
import com.pengtu.gsj.entity.app.Log;
import com.pengtu.gsj.service.system.LogService;

/**
 * 
 * 
 * LogServiceImpl
 * 
 * 2017年4月21日 上午9:57:44
 * 
 * @version 1.0.0
 *
 */
@Transactional
@Service
public class LogServiceImpl implements LogService {
	@Autowired
	private LogDao logDao;

	@Override
	public List<Log> getLogs(QueryFilter queryFilter) {
		return logDao.find(queryFilter);
	}

	@Override
	public Page<Log> findLogs(Page<Log> page, QueryFilter queryFilter) {
		return logDao.findPage(page, queryFilter);
	}

	@Override
	public Log getLog(String id) {
		return logDao.get(id);
	}

	@Override
	public void saveLog(Log log) {
		logDao.save(log);
	}

	@Override
	public void deleteLog(String id) {
		logDao.delete(id);

	}

	@Override
	public List<Log> getAllLog() {
		return logDao.getAll();
	}

	public Map<String,List<Map<String, String>>> getYearMap(List<Log> list) {
		Map<String,List<Map<String, String>>> map=null;
		if(list.size()>0){
			map=new HashMap<String, List<Map<String, String>>>();
			List<Map<String, String>> logList = null;
			Map<String, String> mapValue= null;
			TreeSet<String> yearSet=new TreeSet<String>();
			for(int i=0;i<list.size();i++){
				String opTime = list.get(i).getOpTime();
				yearSet.add(opTime.split("-", 2)[0]);
			}
			for(String year:yearSet){
				logList =new ArrayList<Map<String, String>>();
				mapValue =new TreeMap<String,String>(new Comparator<String>(){
					@Override
					public int compare(String o1, String o2) {
						return o2.compareTo(o1);
					}
				});
				for(int j=0;j<list.size();j++){
					if(year.equals(list.get(j).getOpTime().split("-", 2)[0])){
						mapValue.put(list.get(j).getOpTime().substring(5,19),list.get(j).getRemark());
					}
				}
				logList.add(mapValue);
				map.put(year, logList);
			}
		}
		return map;
	}
	
	
	


}
